/*
 * Copyright (C) 2012  - 2013 The playserver  Project
 * Author:longwuwei
 * All Rights Reserved.
 */

#ifndef MEDIASERVICE_H_
#define MEDIASERVICE_H_

#include "NetService.h"
#include "SvrClient.h"
#include "SvrTask.h"
#include "Svr_log.h"
#include "SvrFileManage.h"
#include "SvrInfo.h"

/**
 * Mediaservice  class define
 */
class Mediaservice:public NetService {
public:
    Mediaservice();
    virtual ~Mediaservice();

    int Svr_Start(void);
    int Svr_Stop(void);
    int Svr_Run(long useconds);
    int Svr_Status(void);

protected:
    /*
    * svr run ,net enginelib function
    */
    NEXT_OPRATION  Svr_TransFile(user_token * token,buf_chunk * sock_buf);
    NEXT_OPRATION  accept_completed(user_token *& token,buf_chunk * sock_buf);
    NEXT_OPRATION  connect_completed(user_token * token,buf_chunk * sock_buf);
    NEXT_OPRATION  receive_completed(user_token * token,buf_chunk * sock_buf);
    NEXT_OPRATION  send_completed(user_token * token,buf_chunk * sock_buf);
    NEXT_OPRATION  trans_heartbeat(user_token * token);
    NEXT_OPRATION  trans_completed(user_token * token,buf_chunk * sock_buf);
    NEXT_OPRATION  recv_or_send_wait_completed(user_token * token,buf_chunk * sock_buf);
    void           close_completed(user_token * token,buf_chunk * sock_buf,NET_ERROR_CODE error);
    int            log_fmt(int nloglvl,const char * lpszFormat, ...);

    /**
    * svr run task ,single thread
    */
    void           Svr_HearBeat(void);
    void           Svr_Run_task(void);
    void           Svr_Handle_Client_Session(void);

    /**
    * svr run time tick
    */
    int            HearBeatTick;

private:
    SvrConfig      svrConfig;
    SvrClient      svrClient;
    SvrTask        svrTask;
    Svr_log        svrLog;
    SvrFileManage  svrFileManage;
    SvrInfo		   svrInfo;
    int            runFlag;
    int            initFlag;
};

#endif /* MEDIASERVICE_H_ */
